﻿Core = {};
Core.String = {};
Core.String.trimHead=function(str){return str.replace(/^(\u3000|\s|\t)*/gi,"")};
Core.String.trimTail=function(str){return str.replace(/(\u3000|\s|\t)*$/gi,"")};
Core.String.trim=function(str){return Core.String.trimHead(Core.String.trimTail(str))};
Core.String.byteLength=function(str){if(typeof str=="undefined"){return 0}var aMatch=str.match(/[^\x00-\x80]/g);return(str.length+(!aMatch?0:aMatch.length))};
Core.String.getLength=function(str){var len=Core.String.trim(str).length;if(len>0){return Math.ceil(Core.String.byteLength(Core.String.trim(str))/2)}else{return 0}};
Core.String.getLengthx=function(str){var len=str.length;if(len>0){return Math.ceil(Core.String.byteLength(str)/2)}else{return 0}};
Core.String.leftB=function(str,len){
    var s=str.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**");
    str=str.slice(0,s.slice(0,len).replace(/\*\*/g," ").replace(/\*/g,"").length);
    if(Core.String.byteLength(str)>len){
    str=str.slice(0,str.length-1)
    }
    return str;
};
Core.String.subStr=function(str, start, len){
    var end = start + len ;
    var strBefore = start == 0 ? '' : Core.String.leftB(str, start-1);
    var strBeforeActualLen = strBefore.length;
    var strBeforeLen = strBefore.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**").length;
    var s=str.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**");

    if(s.length<=end){
        return str=str.slice(strBeforeActualLen,str.length);
    }
    str=str.slice(strBeforeActualLen,strBeforeActualLen + s.slice(start,end).replace(/\*\*/g," ").replace(/\*/g,"").length+1);

    return str;
};
